const url = '?a=1&b=2'

// 方法1：使用URLSearchParams
const urlSearchParems =  new URLSearchParams(url)
const params = Object.fromEntries(urlSearchParems.entries())
console.log(params)

// 方法2：使用split
function getParams(url){
    const res = {}
    if(url.include('?')){
        const str = url.split('?')[1]
        const arr = str.split('&')
        arr.forEach(item => {
            const r = item.split('=')
            const key = r[0]
            const val = r[1]
            res[key] = decodeURIComponent(val) 
        });
    }
    return res
}